package com.pengjunlee.hive.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.pengjunlee.hive.bean.Vehicle;
import com.pengjunlee.hive.bean.VehicleResult;
import com.pengjunlee.hive.service.JedisService;
import com.pengjunlee.hive.utils.ResponseResult;


@RestController
@RequestMapping("/redis")
public class JedisController {
	
	@Autowired
	private JedisService jedisService;
	
	/**
	 * 根据设备号获取车辆的实时位置详情
	 * @param vehicle
	 * @return
	 * @throws Exception
	 */
	@PostMapping("/queryVehicleInfoByTerminalCode")
	public ResponseResult queryVehicleInfoByTerminalCode(@RequestBody Vehicle vehicle) throws Exception {
		try{
			List<VehicleResult> list = jedisService.queryVehicleInfoByTerminalCode(vehicle.getTerminalCode());
			return ResponseResult.success(list);
		}catch(Exception ex){
			return ResponseResult.failure(ex.getMessage());
		}
	}
	
	/**
	 * 根据设备号获取车辆的轨迹信息
	 * @param vehicle
	 * @return
	 * @throws Exception
	 */
	@PostMapping("/queryVehicleTrackInfoByTerminalCode")
	public ResponseResult queryVehicleTrackInfoByTerminalCode(@RequestBody Vehicle vehicle) throws Exception {
		try{
			List<VehicleResult> list = jedisService
					.queryVehicleTrackInfoByTerminalCode(vehicle.getTerminalCode(), vehicle.getStartTime(), vehicle.getEndTime());
			return ResponseResult.success(list);
		}catch(Exception ex){
			return ResponseResult.failure(ex.getMessage());
		}
	}
}